package br.np2tec.soa.servicos;

import java.util.List;
import javax.jws.WebService;
import javax.xml.ws.WebServiceRef;
import br.np2tec.soa.servicos.TaxaContrato;
/**
 *
 * @author Flavio
 */
@WebService()
public class GerarPropostaContratoService {

    @WebServiceRef(wsdlLocation="http://localhost:8080/TratarTaxaContratoDataServiceService/TratarTaxaContratoDataService?WSDL")
    TratarTaxaContratoDataServiceService tratarTaxaContratoDataService;

    @WebServiceRef(wsdlLocation="http://localhost:8080/TratarPropostaContratoDataServiceService/TratarPropostaContratoDataService?WSDL")
    TratarPropostaContratoDataServiceService tratarPropostaContratoDataService;

    @WebServiceRef(wsdlLocation="http://localhost:8080/TratarCreditosConcedidosDataServiceService/TratarCreditosConcedidosDataService?WSDL")
    TratarCreditosConcedidosDataServiceService tratarCreditosConcedidosDataService;

    @WebServiceRef(wsdlLocation="http://localhost:8080/TratarPropostaCreditoDataServiceService/TratarPropostaCreditoDataService?WSDL")
    TratarPropostaCreditoDataServiceService tratarPropostaCreditoDataService;

    public void gerarPropostaContrato(Long numeroPropostaCredito, Integer numeroContrato, String situacaoContrato, List<TaxaContrato> listaTaxaContrato) {

        PropostaCredito propostaCredito = tratarPropostaCreditoDataService.getTratarPropostaCreditoDataServicePort().consultarPropostaCredito(numeroPropostaCredito);

        CreditosConcedidos creditosConcedidos = tratarCreditosConcedidosDataService.getTratarCreditosConcedidosDataServicePort().consultarCreditosConcedidosPorIdPropostaCredito(propostaCredito.getId());

        PropostaContrato propostaContrato = new PropostaContrato();
        propostaContrato.setCreditosConcedidos(creditosConcedidos);
        propostaContrato.setNumeroContrato(numeroContrato);
        propostaContrato.setSituacao(situacaoContrato);
        propostaContrato.getTaxasContrato().addAll(listaTaxaContrato);

       tratarPropostaContratoDataService.getTratarPropostaContratoDataServicePort().incluirPropostaContrato(propostaContrato);

    }

    //TODO confirgurar SMTP
    private void enviarEmail() throws Exception {
        /*Email email = new SimpleEmail();
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator("username", "password"));
        email.setDebug(false);
        email.setHostName("smtp.gmail.com");
        email.setFrom("user@gmail.com");
        email.setSubject("TestMail");
        email.setMsg("This is a test mail ... :-)");
        email.addTo("foo@bar.com");
        email.setTLS(true);
        email.send();*/

    }
}
